//
//  MyInstituCell.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/9/29.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "MyInstituCell.h"
#import "MyInstituModel.h"
@implementation MyInstituCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(void)setModel:(MyInstituModel *)model{
    _model = model;
    UIImageView *iconImageView = [[UIImageView alloc] init];
    [iconImageView sd_setImageWithURL:[NSURL URLWithString:_model.imgPath] placeholderImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:iconImageView];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(125, 72));
        make.left.equalTo(self.contentView.mas_left).offset(scaleLeftAndRight(12));
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    UILabel *namelabel = [[UILabel alloc] init];
    namelabel.font = [UIFont systemFontOfSize:14];
    namelabel.textColor = COLOR_HEX(0x121212);
    namelabel.text = _model.name;
    [self.contentView addSubview:namelabel];
    [namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top).offset(scaleTopAndBottom(12));
        make.left.equalTo(iconImageView.mas_right).offset(scaleLeftAndRight(10));
        make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-10));
        make.height.mas_equalTo(scaleTopAndBottom(14));
    }];
    UILabel *stateLabel = [[UILabel alloc] init];
    stateLabel.text = [self acodingStateBack:_model.state];
    stateLabel.font = [UIFont systemFontOfSize:10];
    stateLabel.textColor = COLOR_HEX(0xB3B3B3);
    [self.contentView addSubview:stateLabel];
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageView.mas_right).offset(scaleLeftAndRight(10));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(scaleTopAndBottom(-12));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(80),scaleTopAndBottom(12)));
    }];
    UILabel *timeLabel = [[UILabel alloc] init];
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"   %@",[self timeBackAccoringValue:_model.foundTime]]];
    NSTextAttachment *attach = [[NSTextAttachment alloc] init];
    attach.image = [UIImage imageNamed:@"矢量智能对象拷贝3"];
    attach.bounds = CGRectMake(0, 0, scaleLeftAndRight(12), scaleTopAndBottom(12));
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attach];
    [attri insertAttributedString:string atIndex:0];
    timeLabel.attributedText = attri;
//    timeLabel.text = [self timeBackAccoringValue:_model.foundTime];
    timeLabel.font = [UIFont systemFontOfSize:10];
    timeLabel.textColor = COLOR_HEX(0xB3B3B3);
    timeLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:timeLabel];
    CGSize labelSize = [_model.foundTime sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:timeLabel.font,NSFontAttributeName, nil]];
    NSLog(@"%lf",labelSize.width);
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-15));
        make.bottom.equalTo(self.contentView.mas_bottom).offset(scaleTopAndBottom(-12));
        make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(labelSize.width), scaleTopAndBottom(12)));
    }];
//    UIImageView *tiemImagev = [[UIImageView alloc] init];
//    tiemImagev.image = [UIImage imageNamed:@"矢量智能对象拷贝3"];
//    [self.contentView addSubview:tiemImagev];
//    [tiemImagev mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.contentView.mas_bottom).offset(scaleTopAndBottom(-12));
//        make.right.equalTo(timeLabel.mas_left).offset(scaleLeftAndRight(-3));
//        make.size.mas_equalTo(CGSizeMake(scaleTopAndBottom(12), scaleTopAndBottom(12)));
//    }];
    UILabel *descripLabel = [[UILabel alloc] init];
    descripLabel.numberOfLines = 0;
    descripLabel.font = [UIFont systemFontOfSize:12];
    descripLabel.textColor = COLOR_HEX(0xABABAB);
    descripLabel.text =_model.Descripsion;
    [self.contentView addSubview:descripLabel];
    [descripLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(namelabel.mas_bottom).offset(scaleTopAndBottom(7));
        make.left.equalTo(iconImageView.mas_right).offset(scaleLeftAndRight(10));
//        make.height.mas_equalTo(scaleTopAndBottom(27));
        make.bottom.equalTo(timeLabel.mas_top).offset(scaleTopAndBottom(-7)); make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-10));
    }];
}
-(NSString *)acodingStateBack:(NSString *)state{
    NSString *stateStr = @"";
    switch ([state integerValue]) {
        case 0:
        {
            stateStr = @"正常";
        }
            break;
        case 1:
        {
            stateStr = @"待审核";
        }
            break;
        case 2:
        {
            stateStr = @"审核未通过";
        }
            break;
        case 3:
        {
            stateStr = @"封号";
        }
            break;
        default:
            break;
    }
    return stateStr;
}
/**
 时间戳转时间
 
 */
-(NSString *)timeBackAccoringValue:(NSString *)timestap{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timestap integerValue]/1000];//现在时间,你可以输出来看下是什么格式
    NSLog(@"这是现%@",confromTimesp);
    NSString *nowtimeStr = [formatter stringFromDate:confromTimesp];
    NSLog(@"这是现在的时间吗%@",nowtimeStr);
    return nowtimeStr;
}
//-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
//    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
//    if (self) {
//        UIImageView *iconImageView = [[UIImageView alloc] init];
//        iconImageView.backgroundColor = [UIColor cyanColor];
//        [self.contentView addSubview:iconImageView];
//        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.size.mas_equalTo(CGSizeMake(125, 72));
//            make.left.equalTo(self.contentView.mas_left).offset(scaleLeftAndRight(12));
//            make.centerY.equalTo(self.contentView.mas_centerY);
//        }];
//        UILabel *namelabel = [[UILabel alloc] init];
//        namelabel.font = [UIFont systemFontOfSize:14];
//        namelabel.textColor = COLOR_HEX(0x121212);
//        namelabel.text = @"泡泡少儿教育";
//        [self.contentView addSubview:namelabel];
//        [namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.contentView.mas_top).offset(scaleTopAndBottom(12));
//            make.left.equalTo(iconImageView.mas_right).offset(scaleLeftAndRight(10));
//            make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-10));
//            make.height.mas_equalTo(scaleTopAndBottom(14));
//        }];
//        UILabel *descripLabel = [[UILabel alloc] init];
//        descripLabel.numberOfLines = 0;
//        descripLabel.font = [UIFont systemFontOfSize:12];
//        descripLabel.textColor = COLOR_HEX(0xABABAB);
//        descripLabel.text = @"都结束了更多立方国际饭店理科高考对方立刻感觉到";
//        [self.contentView addSubview:descripLabel];
//        [descripLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(namelabel.mas_bottom).offset(scaleTopAndBottom(7));
//            make.left.equalTo(iconImageView.mas_right).offset(scaleLeftAndRight(10));
//            make.height.mas_equalTo(scaleTopAndBottom(27));
//            make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-10));
//        }];
//        UILabel *timeLabel = [[UILabel alloc] init];
//        timeLabel.text = @"2017-09-09";
//        timeLabel.font = [UIFont systemFontOfSize:10];
//        timeLabel.textColor = COLOR_HEX(0xB3B3B3);
//        [self.contentView addSubview:timeLabel];
//        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.right.equalTo(self.contentView.mas_right).offset(scaleLeftAndRight(-15));
//            make.bottom.equalTo(self.contentView.mas_bottom).offset(scaleTopAndBottom(-12));
//            make.size.mas_equalTo(CGSizeMake(scaleLeftAndRight(55), scaleTopAndBottom(12)));
//        }];
//        UIImageView *tiemImagev = [[UIImageView alloc] init];
//        [self.contentView addSubview:tiemImagev];
//        [tiemImagev mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.bottom.equalTo(self.contentView.mas_bottom).offset(scaleTopAndBottom(-12));
//            make.right.equalTo(timeLabel.mas_left).offset(scaleLeftAndRight(-3));
//            make.size.mas_equalTo(CGSizeMake(scaleTopAndBottom(12), scaleTopAndBottom(12)));
//        }];
//    }
//    return self;
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
